﻿Public Class ADDRESSTYPE

    Dim connect As CONDB = CONDB.NewConnection()
    ' Dim connectlocal As conlocal = conlocal.NewConnection

    Dim PROVIDER_MASADDRESSTYPE As New PROVIDERSCLASS

    Private Sub ADDRESSTYPE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridaddresstype()

        DesignForm(Me)
        DesignGrid(MASSADDRESSTYPEGrid)

        PROVIDER_MASADDRESSTYPE.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridaddresstype()
        Dim objSelectDataaddresstype As New masaddresstype
        Dim MASADDRESSTYPE As DataTable
        MASADDRESSTYPE = connect.GetTable(objSelectDataaddresstype.selectaddresstype_)
        MASSADDRESSTYPEGrid.PrimaryGrid.DataSource = MASADDRESSTYPE
    End Sub

    Private Sub MASSADDRESSTYPEGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASSADDRESSTYPEGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภท").Value() IsNot DBNull.Value Then
            ADDRESSTYPEIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสประเภท").Value()
        Else
            ADDRESSTYPEIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภทที่อยู่").Value() IsNot DBNull.Value Then
            ADTDESCTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ประเภทที่อยู่").Value()
        Else
            ADTDESCTxt.Text = ""
        End If
        addAddresstype.Enabled = False
    End Sub

    Private Sub addAddresstype_Click_1(sender As Object, e As EventArgs) Handles addAddresstype.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASADDRESSTYPE.PADD_ = True Then
                Dim objInsertData As New masaddresstype
                objInsertData.ADTDESC_ = ADTDESCTxt.Text
                objInsertData.insertMasaddresstypeData()

                SelectDatagridaddresstype()

                ADDRESSTYPEIDTxt.Text = ""
                ADTDESCTxt.Text = ""
            Else
                MsgBox(PROVIDER_MASADDRESSTYPE.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editAddresstype_Click_1(sender As Object, e As EventArgs) Handles editAddresstype.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASADDRESSTYPE.PUPD_ = True Then
                Dim editStat As Integer
                editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลประเภทที่อยู่ดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                If editStat = 1 Then
                    Dim objEditData As New masaddresstype
                    objEditData.massaddresstypeID_ = CInt(ADDRESSTYPEIDTxt.Text)
                    objEditData.ADTDESC_ = ADTDESCTxt.Text
                    objEditData.editMasaddresstypeData()

                    SelectDatagridaddresstype()

                    ADDRESSTYPEIDTxt.Text = ""
                    ADTDESCTxt.Text = ""
                End If
                addAddresstype.Enabled = False
            Else
                MsgBox(PROVIDER_MASADDRESSTYPE.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL(masaddresstype.Text)
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL(masaddresstype.Text)
        nextform.ShowDialog()
    End Sub
End Class